﻿<UserControl x:Class="TimeBarPlugin.Historical.ControlPanel"
   
			 xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
			 xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
			 xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
			 xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
			 mc:Ignorable="d"
			 
             xmlns:Converters="clr-namespace:Utils.Wpf.Converters;assembly=Utils"
             xmlns:UserControls="clr-namespace:Plugins.UserControls;assembly=Plugins"
             xmlns:Utils="clr-namespace:Utils.Wpf;assembly=Utils" xmlns:FD2="clr-namespace:TimeBarPlugin"
             xmlns:TB="clr-namespace:TimeBarPlugin.Historical"
			 
             d:DataContext="{d:DesignInstance Type=TB:ControlPanelVM}"
			 
			 Utils:AnimatorOnVisibilityChange.AnimationType="Fade"
			 Utils:AnimatorOnVisibilityChange.Duration="1000"
			 Visibility="Collapsed"
			 Background="#1F1F1F" >

    <UserControl.Resources>
        <ResourceDictionary>
            <Converters:BooleanNotConverter x:Key="BooleanNotConverter" />
			<Converters:NegatedBooleanToVisibilityConverter x:Key="NegatedBooleanToVisibilityConverter" />
            <ResourceDictionary.MergedDictionaries>
				<ResourceDictionary Source="pack://application:,,,/Plugins;component/PluginTheme.xaml" />
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
    </UserControl.Resources>

    <UserControl.IsEnabled>
        <Binding Path="IsBusy" Converter="{StaticResource BooleanNotConverter}" />
    </UserControl.IsEnabled>

    <!--<UserControl.Background>
		<StaticResource ResourceKey="GridBackground" />
	</UserControl.Background>-->

    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
        </Grid.RowDefinitions>
		<Grid.ColumnDefinitions>
			<ColumnDefinition Width="*" />
		</Grid.ColumnDefinitions>
		
		<Border Grid.Row="0" BorderThickness="1,1,1,0" BorderBrush="{StaticResource ControlPanelLines}" CornerRadius="10,10,0,0" Background="#DCDCDC" >
            <StackPanel Orientation="Horizontal" HorizontalAlignment="Center" >
				<TextBlock Grid.Row="0" Text="Time Bar Strategy Historical Plugin" Margin="3" Foreground="Black" FontWeight="Bold" />
                <Image Source="..\Resources\Info.ico" Margin="10,0,0,0" >
                    <Image.ToolTip>
						<StackPanel>
							<TextBlock Foreground="Black" FontWeight="Bold" Text="Time Bar Strategy Historical Plugin" />
							<TextBlock Foreground="Black" >
								The main idea is to execute a lot of small operations trying to profit small raises and falls.<LineBreak/>
								We try to get small loses and bigger wins with a 50% ratio (aprox) of winners. <LineBreak/>
								It' a derivate of the Full Day plugin focused on small time frames.
							</TextBlock>
						</StackPanel>
					</Image.ToolTip>
                    <Image.Style>
                        <Style>
                            <Style.Triggers>
                                <Trigger Property="Image.IsEnabled" Value="False" >
                                    <Setter Property="Image.Opacity" Value="0.5" />
                                </Trigger>
                            </Style.Triggers>
                        </Style>
                    </Image.Style>
                </Image>
            </StackPanel>
        </Border>
        <Border Grid.Row="1" BorderThickness="1" BorderBrush="{StaticResource ControlPanelLines}" Padding="6" CornerRadius="0,0,10,10" >
            <Grid>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="Auto" />
                    <ColumnDefinition Width="Auto" />
                    <ColumnDefinition Width="Auto" />
                    <ColumnDefinition Width="Auto" />
                    <ColumnDefinition Width="Auto" />
                    <ColumnDefinition Width="Auto" />
                    <ColumnDefinition Width="Auto" />
                    <ColumnDefinition Width="Auto" />
                    <ColumnDefinition Width="Auto" />
                    <ColumnDefinition Width="Auto" />
                    <ColumnDefinition Width="Auto" />
                    <ColumnDefinition Width="Auto" />
                    <ColumnDefinition Width="*" />
					<ColumnDefinition Width="Auto" />
					<ColumnDefinition Width="Auto" />
                </Grid.ColumnDefinitions>
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto" />
                </Grid.RowDefinitions>

				<!-- Preset Selector -->
				<Expander Grid.Column="0" IsExpanded="True" ExpandDirection="Left" >
					<Expander.Header>
						<ItemsControl TextElement.FontSize="11" ItemsSource="Presets" Foreground="{StaticResource FontBrush}" Visibility="{Binding IsExpanded, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type Expander}, AncestorLevel=1}, Converter={StaticResource NegatedBooleanToVisibilityConverter}}" />
					</Expander.Header>
					<UserControls:PresetSelector DataContext="{Binding PresetSelectorVM}" IsSaveEnabled="{Binding IsEnabled, ElementName=ExecuteButton}" />
				</Expander>

				<!-- Separator -->
				<Border Grid.Column="1" BorderBrush="{StaticResource SelectedRowBrush}" BorderThickness="1" Margin="10,0,10,0" />

				<!-- Stock Selection -->
				<Expander Grid.Column="2" IsExpanded="True" ExpandDirection="Left" >
					<Expander.Header>
						<ItemsControl TextElement.FontSize="11" ItemsSource="Stocks" Foreground="{StaticResource FontBrush}" Visibility="{Binding IsExpanded, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type Expander}, AncestorLevel=1}, Converter={StaticResource NegatedBooleanToVisibilityConverter}}" />
					</Expander.Header>
					<UserControls:StockSelector DataContext="{Binding StockSelectorVM}" />
				</Expander>

				<!-- Separator -->
                <Border Grid.Column="3" BorderBrush="{StaticResource SelectedRowBrush}" BorderThickness="1" Margin="10,0,10,0" />

                <!-- Date Selection -->
				<Expander Grid.Column="4" IsExpanded="True" ExpandDirection="Left" >
					<Expander.Header>
						<ItemsControl TextElement.FontSize="11" ItemsSource="Dates" Foreground="{StaticResource FontBrush}" Visibility="{Binding IsExpanded, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type Expander}, AncestorLevel=1}, Converter={StaticResource NegatedBooleanToVisibilityConverter}}" />
					</Expander.Header>
					<ContentControl IsEnabled="{Binding StockSelectorVM.IsStockSelected}" >
						<UserControls:DateSelector DataContext="{Binding DateSelectorVM}" />
					</ContentControl>
				</Expander>

				<!-- Separator -->
                <Border Grid.Row="0" Grid.Column="5" BorderBrush="{StaticResource SelectedRowBrush}" BorderThickness="1" Margin="10,0,10,0" />

                <!-- Hour Limits -->
				<Expander Grid.Column="6" IsExpanded="True" ExpandDirection="Left" >
					<Expander.Header>
						<ItemsControl TextElement.FontSize="11" ItemsSource="Hours" Foreground="{StaticResource FontBrush}" Visibility="{Binding IsExpanded, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type Expander}, AncestorLevel=1}, Converter={StaticResource NegatedBooleanToVisibilityConverter}}" />
					</Expander.Header>
					<ContentControl IsEnabled="{Binding StockSelectorVM.IsStockSelected}" >
						<UserControls:HourSelector DataContext="{Binding HourSelectorVM}"/>
					</ContentControl>
				</Expander>

				<!-- Separator -->
                <Border Grid.Column="7" BorderBrush="{StaticResource SelectedRowBrush}" BorderThickness="1" Margin="10,0,10,0" />

                <!-- Stock Parameters -->
				<Expander Grid.Column="8" IsExpanded="True" ExpandDirection="Left" >
					<Expander.Header>
						<ItemsControl TextElement.FontSize="11" ItemsSource="Fees" Foreground="{StaticResource FontBrush}" Visibility="{Binding IsExpanded, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type Expander}, AncestorLevel=1}, Converter={StaticResource NegatedBooleanToVisibilityConverter}}" />
					</Expander.Header>
					<ContentControl IsEnabled="{Binding StockSelectorVM.IsStockSelected}" >
						<UserControls:StockParametersSelector DataContext="{Binding StockParametersSelectorVM}"/>
					</ContentControl>
				</Expander>

				<!-- Separator -->
                <Border Grid.Row="0" Grid.Column="9" BorderBrush="{StaticResource SelectedRowBrush}" BorderThickness="1" Margin="10,0,10,0" />

                <!-- Parameters -->
				<Expander Grid.Column="10" IsExpanded="True" ExpandDirection="Left" >
					<Expander.Header>
						<ItemsControl TextElement.FontSize="11" ItemsSource="Options" Foreground="{StaticResource FontBrush}" Visibility="{Binding IsExpanded, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type Expander}, AncestorLevel=1}, Converter={StaticResource NegatedBooleanToVisibilityConverter}}" />
					</Expander.Header>
					<ContentControl IsEnabled="{Binding StockSelectorVM.IsStockSelected}" >
						<FD2:StrategyControl DataContext="{Binding StrategyControlVM}"/>
					</ContentControl>
				</Expander>

				<!-- Separator -->
                <Border Grid.Row="0" Grid.Column="11" BorderBrush="{StaticResource SelectedRowBrush}" BorderThickness="1" Margin="10,0,10,0" />

				<!-- Stock Parameters -->
				<Expander Grid.Column="12" IsExpanded="False" ExpandDirection="Left" >
					<Expander.Header>
						<ItemsControl TextElement.FontSize="11" ItemsSource="Charts" Foreground="{StaticResource FontBrush}" Visibility="{Binding IsExpanded, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type Expander}, AncestorLevel=1}, Converter={StaticResource NegatedBooleanToVisibilityConverter}}" />
					</Expander.Header>
					<ContentControl IsEnabled="{Binding StockSelectorVM.IsStockSelected}" >
						<FD2:CustomDataParameters DataContext="{Binding CustomDataParametersVM}"/>
					</ContentControl>
				</Expander>

				<!-- Separator -->
				<Border Grid.Row="0" Grid.Column="13" BorderBrush="{StaticResource SelectedRowBrush}" BorderThickness="1" Margin="10,0,10,0" />
				
				<!-- Go Button -->
                <Button Grid.Row="0" Grid.Column="14" Command="{Binding RunStrategyCommand}" x:Name="ExecuteButton" >
                    <Button.Style>
                        <Style>
                            <Style.Triggers>
                                <Trigger Property="Button.IsEnabled" Value="False" >
                                    <Setter Property="Button.Opacity" Value="0.5" />
                                </Trigger>
                            </Style.Triggers>
                        </Style>
                    </Button.Style>
                    <Image Source="../Resources/Execute.ico" />
                    <Button.ToolTip>
                        <StackPanel>
                            <TextBlock Foreground="Black" FontWeight="Bold" Text="Exectute" />
                            <TextBlock Foreground="Black" Text="Execute the current strategy with the selected parameters" />
                        </StackPanel>
                    </Button.ToolTip>
                </Button>
            </Grid>
        </Border>
    </Grid>
</UserControl>
